import { cacheTools, promptBox, toast } from 'nc-lightapp-front';
export default class cardAction {
	constructor(comp) {
		this.comp = comp;
	}

	setDetailData = (record, index) => {
		const { action, props } = this.comp;
		const { dispatch, transDimission, cardPagination, form, cardTable,button} = props;
		let pkId = record.values !== undefined ? record.values.pk_bill.value : record;
		dispatch({
			type: 'transDimission/getDetailData',
			payload: {
				postData: {
					type: transDimission.pagiType,
					pk_org: transDimission.hrorgobj.refpk,
					pk_bill: pkId
				}
			}
		}).then((res) => {
			let hasDatas = JSON.stringify(res.data) === '{}' ? false : true;
			let allpks = cacheTools.get('allpks');
			// 改变table的status
			// 在edit mode下,会重写table,导致template中写的render方法失效
			if (transDimission.showMode === 'card-edit') {
				cardTable.getStatus('handoverdetailmygrid') !== 'edit' &&
					cardTable.setStatus('handoverdetailmygrid', 'edit');
			} else {
				cardTable.getStatus('handoverdetailmygrid') === 'edit' &&
					cardTable.setStatus('handoverdetailmygrid', 'browse');
			}
			if (hasDatas) {
				form.setAllFormValue({ psninfoheadform: { rows: res.data.head['psninfoheadform'].rows } });
				// 卡片式图中table默认都是展开
				cardTable.toggleCardTable([ 'handoverdetailmygrid', 'handoverdetailgrid' ], true);
				cardTable.setTableData('handoverdetailmygrid', res.data.bodymycheck['handoverdetailgrid']);
				cardTable.setTableData('handoverdetailgrid', res.data.bodyall['handoverdetailgrid']);
				cardPagination.setCardPaginationId({ id: allpks[index], status: 1 });
			}
		});
	};
}
